home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / pgpPgp5.tcl.z / pgpPgp5.tcl
Text File  |  2002-07-08  |  9KB  |  234 lines

  1. # pgpPgp5.tcl
  2.  
  3. # $Log: pgpPgp5.tcl,v $
  4. # Revision 1.7  2001/01/04 02:24:46  bmah
  5. # Add +force to PGP5 flags.  This fixes
  6. # a bug where PGP5 couldn't verify clearsigned messages under some
  7. # circumstances.  In my testing I was only able to make this happen
  8. # with clearsigned messages and multipart/mime, which produces some
  9. # rather strange output anyways.  But this doesn't seem to hurt
  10. # anything.
  11. #
  12. # Submitted-by:    Dave Tweten <tweten@nas.nasa.gov>, via the FreeBSD
  13. #         Project
  14. #
  15. # Revision 1.6  2000/04/18 18:38:33  valdis
  16. # Fix quote character to use ascii rather than iso8859-ish one
  17. #
  18. # Revision 1.5  1999/09/30 03:51:07  kchrist
  19. # pgp($v,cmd_Beauty) was getting in the way of pgp($v,cmd_User) for
  20. # v=gpg so I had to rearrange things a bit.
  21. #
  22. # Revision 1.4  1999/09/27 23:18:46  kchrist
  23. # More PGP changes. Consolidated passphrase entry to sedit field or
  24. # pgpExec routine. Made the pgp-sedit field aware of pgp(keeppass)
  25. # and pgp(echopass). Moved pgp(keeppass), pgp(echopass) and
  26. # pgp(grabfocus) to PGP General Interface. Fixed a minor bug left
  27. # over from my previous GUI changes. Made pgp-sedit field appear and
  28. # disappear based on its enable preference setting.
  29. #
  30. # Revision 1.3  1999/08/13 00:39:06  bmah
  31. # Fix a number of key/passphrase management problems:  pgpsedit now
  32. # manages PGP versions, keys, and passphrases on a per-window
  33. # basis.  Decryption now works when no passphrases are cached.
  34. # One timeout parameter controls passphrases for all PGP
  35. # versions.  seditpgp UI slightly modified.
  36. #
  37. # Revision 1.2  1999/08/03 04:05:56  bmah
  38. # Merge support for PGP2/PGP5/GPG from multipgp branch.
  39. #
  40. # Revision 1.1.4.1  1999/06/14 20:05:16  gruber
  41. # updated multipgp interface
  42. #
  43. # Revision 1.1  1999/06/14 15:14:55  markus
  44. # added files
  45. #
  46. # Revision 1.4  1998/12/08 15:04:46  markus
  47. # modified cmd_cleanOutput
  48. #
  49. # Revision 1.3  1998/12/06 16:27:22  markus
  50. # Added DecryptExpect and subkey support
  51. #
  52. # Revision 1.2  1998/12/02 20:06:33  markus
  53. # Few fixes in cmd_cleanOutput
  54. #
  55. # Revision 1.1.1.1  1998/11/24 22:34:46  markus
  56. # Initial revision
  57. #
  58.  
  59. #######################################################################
  60. # PGP5 CONFIG
  61.  
  62. proc Pgp_pgp5_Init {} {
  63. global pgp
  64. ###
  65.  
  66. # Yes, we need network keyfetching
  67. Pgp_WWW_Init
  68.  
  69. set pgp(pref,HKPkeyserverUrl) { HKPkeyserverUrl HKPKeyServerUrl {keys.pgp.com}
  70. {Horowitz Key Protocol Server}
  71. "The hkp (Horowitz Key Protokol) is a subset of the http.
  72. It's used to transfer keys to and from a keyserver.
  73. Give here a hkp server name." }
  74.  
  75.  
  76. # Needed for Preferences
  77. set pgp(pgp5,description) "PGP5 is the new Pretty Good Privacy Package from Zimmermann."
  78. set pgp(pgp5,prefs) [list rfc822 \
  79.                           choosekey useexpectk cacheids minmatch showinline \
  80.                           shortmsgs autoextract \
  81.                           keyserver keyquerymethod HKPkeyserverUrl keyserverUrl keyothermethod ]
  82.  
  83. # this is called when preferences are set
  84. proc Pgp_pgp5_Preferences {} {
  85. }
  86.  
  87. # digest algo
  88. set pgp(pgp5,digestalgo) sha1
  89.  
  90.  
  91. #######################################################################
  92. # Flags, Commands, Patterns, Settings
  93. #
  94. # Should config file be parsed
  95. set pgp(pgp5,parse_config) 1
  96.  
  97. #######
  98. # Exec
  99. #############
  100. # Exec_Batch
  101. # Batchmode flags
  102. set pgp(pgp5,flags_batch) {+armorlines=0 +batchmode=on +force +verbose=0}
  103. #
  104. proc Pgp_pgp5_PassFdSet {} {
  105.     global env
  106.     set env(PGPPASSFD) 0
  107. }
  108. #
  109. proc Pgp_pgp5_PassFdUnset {} {
  110.     global env
  111.     catch { unset env(PGPPASSFD) }
  112. }
  113.  
  114. ###################
  115. # Exec_Interactive
  116. # Interactive flags
  117. set pgp(pgp5,flags_interactive) {+armorlines=0}
  118. # Cleanup output
  119. set pgp(pgp5,cmd_cleanOutput) { regsub -all "\[\x0d\x07]" $output {} output
  120.                                 regsub "^.*\nEnter pass phrase:" $output {} output
  121.                                 regsub "^.*\nPass phrase is good." $output {} output
  122.                                 regsub "^.*Opening file\[^\n\]*\n" $output {} output
  123.                                 regsub -all "\nOpening file\[^\n\]*" $output {} output
  124.                                 set output [string trim $output] }
  125.  
  126. ###############
  127. # Exec_KeyList
  128. # List pubkeys args prototype
  129. set pgp(pgp5,args_listPub) {-l \"$pattern\"}
  130. # List seckeys args prototype
  131. set pgp(pgp5,args_listSec) $pgp(pgp5,args_listPub)
  132. # Pattern that matches out revoked and nonvalid keys
  133. set pgp(pgp5,pat_dropKeys) \
  134.          "((\n(pub|sec)\[\\?!\\*]? \[^\n]+\\*REVOKED\\*\[^\n]+(\n(sub) \[^\n]+)?(\n(uid) \[^\n]+)+)"
  135. append pgp(pgp5,pat_dropKeys) \
  136.          "(\n(pub@|pub%|sec@|ret) \[^\n]+(\n(sub) \[^n]+)?(\n(uid) \[^n]+)+))"
  137. # Where to split up the listKeys raw output to form a list
  138. set pgp(pgp5,pat_splitKeys) "\n"
  139. # Patterns that match out interesting keys
  140. set pgp(pgp5,pat_keySec) {^.*(sec)[\?!\*\+]? +[0-9]+ +0x([0-9A-F]+) +[0-9]+-[0-9]+-[0-9]+ +[^ ]+ +([^ ]+).*$}
  141. set pgp(pgp5,pat_keySec_sub) {^.*(sub)[\?!\*\+]? +[0-9]+ +0x([0-9A-F]+) +[0-9]+-[0-9]+-[0-9]+ +[^ ]+ +([^ ]+).*$}
  142. set pgp(pgp5,pat_keyPub) {^.*(sec|pub)[\?!\*\+]? +[0-9]+ +0x([0-9A-F]+) +[0-9]+-[0-9]+-[0-9]+ +[^ ]+ +([^ ]+).*$}
  143. set pgp(pgp5,pat_keyPub_sub) $pgp(pgp5,pat_keySec_sub)
  144. set pgp(pgp5,pat_uid) {^.*uid +(.*)$}
  145. # TclCmd to match out userid and keyid
  146. set pgp(pgp5,cmd_keyMatch) { regexp $keypattern $line {} {} keyid algo }
  147. set pgp(pgp5,cmd_keyMatch_sub) { regexp $subkeypattern $line {} {} keyid algo }
  148. set pgp(pgp5,cmd_uidMatch) { regexp $uidpattern $line {} userid }
  149.  
  150. ###############
  151. # Exec_GetKeys
  152. set pgp(pgp5,args_exportKey) {-x $keyid -o $file}
  153.  
  154. ###############
  155. # Exec_Encrypt
  156. set pgp(pgp5,args_encrypt) {[concat -at $in -o $out [foreach id [Pgp_Misc_Map key {lindex $key 0} $tokeys] {lappend recips -r $id}; set recips]]}
  157.  
  158. ###################
  159. # Exec_EncryptSign
  160. set pgp(pgp5,args_encryptSign) {[concat -ast $in -o $out -u $keyid [foreach id [Pgp_Misc_Map key {lindex $key 0} $tokeys] {lappend recips -r $id}; set recips]]}
  161.  
  162. ############
  163. # Exec_Sign
  164. set pgp(pgp5,args_signClear) {+clearsig=on -at $in -u $keyid -o $out}
  165. set pgp(pgp5,args_signBinary) {+clearsig=off -at $in -u $keyid -o $out}
  166.  
  167. ####################
  168. # Exec_SignDetached
  169. set pgp(pgp5,args_signDetached) {-abt $in -u $keyid -o $out}
  170.  
  171. #####################
  172. # Exec_CheckPassword
  173. set pgp(pgp5,pat_checkError) "(Cannot\[^\n]*)\n"
  174.  
  175. ###############
  176. # Exec_Decrypt
  177. set pgp(pgp5,args_decrypt) {$in -o $out}
  178.  
  179. #####################
  180. # Exec_DecryptExpect
  181. set pgp(pgp5,expectpat,passprompt) {Enter pass phrase: }
  182. set pgp(pgp5,expectpat,conventional) {Message is conventionally encrypted.} ;# matches nothing
  183. set pgp(pgp5,expectpat,publickey) "Need a pass phrase\[^\n\]*\n\[^\n\]*Key ID (\[A-F0-9\]+), \[^\n\]*"
  184. set pgp(pgp5,expectpat,secretmissing) {(Cannot decrypt.*).(It can only be decrypted by:.*)}
  185. set pgp(pgp5,expectpat,nopgpfile) {(This is no ciphertext file.)} ;# matches nothing
  186. set pgp(pgp5,cmd_DecryptExpect) {pgpv +armorlines=0 +batchmode=off +verbose=0 $infile -o $outfile}
  187.  
  188. ##############
  189. # Exec_Verify
  190. set pgp(pgp5,args_verifyOnly) {$in}
  191. set pgp(pgp5,args_verifyOut) {$in -o $out}
  192.  
  193. ######################
  194. # Exec_VerifyDetached
  195. set pgp(pgp5,args_verifyDetached) {$sig}
  196.  
  197. ###################
  198. # Exec_ExtractKeys
  199. set pgp(pgp5,args_importKey) {-a $file}
  200.  
  201. #########################
  202. # ShowMessage keypattern
  203. set pgp(pgp5,pat_validKeys) "\n(Type.*\n(sig|pub|sec|sub|SIG|ret|uid)\[^\n]*)"
  204.  
  205. ##################
  206. # InterpretOutput
  207. # command that matches out keyid in pgp output
  208. set pgp(pgp5,cmd_Keyid) {if {![regexp -nocase {key id ([0-9a-f]+)} $in {} pgpresult(keyid)]} {
  209.                                 regexp {0x([0-9A-F]+)} $in {} pgpresult(keyid) } }
  210. # command that tailors output to be nice looking
  211. set pgp(pgp5,cmd_Beauty) {
  212.      set pgpresult(msg) $redin
  213.      regsub -all "(\nOpening file \"\[^\"\]*\" type text\\.)|(Opening file \"\[^\"\]*\" type text\\.\n)" $pgpresult(msg) {} pgpresult(msg)
  214.      regsub -all "Pass phrase is good\\.\n?" $pgpresult(msg) {} pgpresult(msg)
  215.      regsub -all "Message is encrypted\\.\n?" $pgpresult(msg) {} pgpresult(msg)
  216.      set pgpresult(msg) [string trim $pgpresult(msg)]
  217. }
  218. # patterns for interpreting output
  219. set pgp(pgp5,pat_SecretMissing) {Cannot decrypt.*can only be decrypted by.*}
  220. set pgp(pgp5,pat_PublicMissing) {Signature by unknown keyid.*}
  221. set pgp(pgp5,pat_GoodSignature) {Good signature.*}
  222. set pgp(pgp5,pat_Untrusted) {WARNING:.*is not trusted.*}
  223. set pgp(pgp5,pat_BadSignature) {BAD signature.*}
  224. set pgp(pgp5,pat_UnknownError) {ERROR}
  225. # command that matches out the Originator
  226. set pgp(pgp5,cmd_User) {regexp {by key[^"]*("[^"]*")} $in {} user}
  227.  
  228. ##################
  229. # WWW_QueryHKPKey
  230. set pgp(pgp5,args_HKPimport) {-a hkp://${server}/0x$id}
  231.  
  232. ###
  233. }
  234.